package com.advice;


import com.domain.Result;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import com.exception.CommonException;

import static com.constant.CommonError.UNKOWN_ERROR;


/**
 * @author lxr
 * @version 1.0
 * @describe 全局异常处理器
 * @date 2024/6/18 15:22
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler
    public Result exceptionHandler(RuntimeException ex){
        log.error("异常信息：{}", ex.getMessage());
        Class<? extends RuntimeException> aClass = ex.getClass();
        if(aClass != CommonException.class){
            return Result.error(UNKOWN_ERROR);
        }
        return Result.error(ex.getMessage());
    }

}
